const path = require('path')
const webpack = require('webpack')
const { override, fixBabelImports, addLessLoader, addWebpackPlugin, disableEsLint, addWebpackAlias } = require('customize-cra')
const config = require('./config/env.config')

const _DIR_ = process.cwd()
const _PROD_ = process.env.NODE_ENV === 'production'
const _ENV_ = process.env.BUILD_ENV || 'development'	//build环境

_PROD_ && console.log(`
********************
Build with ${_ENV_}...
********************
`)

module.exports = {
	webpack: override(
		disableEsLint(),
		fixBabelImports('import', {
			libraryName: 'antd',
			libraryDirectory: 'es',
			style: true,
		}),
		addLessLoader({
			javascriptEnabled: true,
			modifyVars: { 'hack': `true;@import "${_DIR_}/src/less/theme.less";` }
		}),
		addWebpackPlugin(
			new webpack.DefinePlugin({
				$PROD: _ENV_ === 'production',
				$HOST: JSON.stringify(config[_ENV_].HOST),
				$PDF_HOST: JSON.stringify(config[_ENV_].PDF_HOST)
			})
		),
		addWebpackAlias({
			'@': path.join(process.cwd(), 'src')
		})
	)
}
